package ifrn.pds.siem.banco;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import ifrn.pds.siem.ementa.Ementa;

public class Alterar implements AlterarDAO {
	public Banco banco;

	public Alterar() {
		banco = new Banco();
	}

	public boolean alterarEmenta(Ementa ementa) {
		try {
			if (!banco.isConnected()) {
				banco.conectar();
			}
			PreparedStatement ps = banco.conexao
					.prepareStatement("update identificacao set atual  =  0 where disciplina = '"
							+ ementa.getIdentificacao().getDisciplina() + "'");
			ps.executeUpdate();
			ps = banco.conexao
					.prepareStatement("insert into identificacao values (?,?,?,?,?,?,?)");
			ps.setString(1, ementa.getIdentificacao().getCurso());
			ps.setString(2, ementa.getIdentificacao().getArea());
			ps.setString(3, ementa.getIdentificacao().getPeriodo());
			ps.setString(4, ementa.getIdentificacao().getCh());
			ps.setString(5, ementa.getIdentificacao().getDisciplina());
			ps.setInt(6, ementa.getIdentificacao().getAno());
			ps.setBoolean(7, ementa.getIdentificacao().isAtual());
			ps.executeUpdate();
			ps = banco.conexao
					.prepareStatement("insert into corpo values (?,?,?,?,?,?)");
			ps.setString(1, ementa.getCorpo().getTopicos());
			ps.setString(2, ementa.getCorpo().getPreReq());
			ps.setString(3, ementa.getCorpo().getObjetivos());
			ps.setString(4, ementa.getCorpo().getConteudo());
			ps.setString(5, ementa.getCorpo().getProcedimentos());
			ps.setString(6, ementa.getCorpo().getAvaliacao());
			ps.executeUpdate();
			ps = banco.conexao
					.prepareStatement("insert into informacoesadicionais values (?,?,?)");
			ps.setString(1, ementa.getInfoAdcionais().getBb());
			ps.setString(2, ementa.getInfoAdcionais().getBc());
			ps.setString(3, ementa.getInfoAdcionais().getInfo());
			ps.executeUpdate();

			return true;
		} catch (SQLException e) {
			System.err.println("erro ao alterar");
			return false;
		}
	}
}
